#include "Share.h"

Thread_Group::Thread_Group( void )
{
}

Thread_Group::~Thread_Group( void )
{
	for( list<Thread*>::iterator iter = threads_.begin( );
	        iter != threads_.end( );
	        ++ iter )
		delete( *iter );
}

void Thread_Group::join_all( )
{
	for( list<Thread*>::iterator iter = threads_.begin( );
	        iter != threads_.end( );
	        ++ iter )
		( *iter )->join( );
}

Thread *Thread_Group::create_thread( )
{
	Thread *thread = new Thread( );

	Guard<Thread_Mutex> guard( mutex_ );

	threads_.push_back( thread );

	return thread;
}

void Thread_Group::add_thread( Thread *thread )
{
	Guard<Thread_Mutex> guard( mutex_ );
	threads_.push_back( thread );
}

void Thread_Group::remove_thread( Thread *thread )
{
	Guard<Thread_Mutex> guard( mutex_ );
	list<Thread*>::iterator iter =
	    std::find( threads_.begin( ), threads_.end( ), thread );
	threads_.erase( iter );
}

